﻿using AdverseEventReportSystem.BLL.SchedulingSystem;
using AdverseEventReportSystem.Core;
using System;

namespace AdverseEventReportSystem.BLL.Scheduling
{
    /// <summary>
    /// 班别相关
    /// </summary>
    public class ScheduleManager
    {
        /// <summary>
        /// 保存班别
        /// </summary>
        /// <param name="schedulingCategory">对象</param>
        /// <returns></returns>
        public static OperateResult SaveScheduleType(SchedulingCategory schedulingCategory)
        {
            OperateResult resultInfo = new OperateResult();
            try
            {
                SchedulingSystemSoapClient service = new SchedulingSystemSoapClient();
                ResultHelperOfBoolean result = service.SaveScheduleType(schedulingCategory);
                if (result.S)
                {
                    resultInfo.Result = 1;
                    resultInfo.Body = result.M;
                }
                else
                {
                    resultInfo.Result = 0;
                    resultInfo.Body = result.M;
                }
            }
            catch (Exception ex)
            {
                resultInfo.Result = 0;
                resultInfo.Body = ex.Message;
            }
            return resultInfo;
        }

        /// <summary>
        /// 获取班别
        /// </summary>
        /// <param name="pageIndex">页索引</param>
        /// <param name="pageSize">页大小</param>
        /// <param name="type">排班类型</param>
        /// <param name="illareaType">病区</param>
        /// <returns></returns>
        public static OperateResult GetScheduleTypeList(int pageIndex, int pageSize, string type, string illareaType)
        {
            OperateResult resultInfo = new OperateResult();
            try
            {
                SchedulingSystemSoapClient service = new SchedulingSystemSoapClient();
                ResultHelperOfString result = service.GeScheduleTypeListForPage(pageIndex, pageSize, type, illareaType);
                if (result.S)
                {
                    resultInfo.Result = 1;
                    resultInfo.Body = result.D;
                }
                else
                {
                    resultInfo.Result = 0;
                    resultInfo.Body = result.M;
                }
            }
            catch (Exception ex)
            {
                resultInfo.Result = 0;
                resultInfo.Body = ex.Message;
            }
            return resultInfo;
        }
        /// <summary>
        /// 获取单个班别
        /// </summary>
        /// <param name="id">Id</param>
        /// <returns></returns>
        public static OperateResult GetScheduleType(int id)
        {
            OperateResult resultInfo = new OperateResult();
            try
            {
                SchedulingSystemSoapClient service = new SchedulingSystemSoapClient();
                ResultHelperOfSchedulingCategory result = service.GetScheduleType(id);
                if (result.S)
                {
                    resultInfo.Result = 1;
                    resultInfo.Body = result.D;
                }
                else
                {
                    resultInfo.Result = 0;
                    resultInfo.Body = result.M;
                }
            }
            catch (Exception ex)
            {
                resultInfo.Result = 0;
                resultInfo.Body = ex.Message;
            }
            return resultInfo;
        }

        /// <summary>
        /// 校验班别状态
        /// </summary>
        /// <param name="id">Id</param>
        /// <returns></returns>
        public static OperateResult CheckScheduingType(int id)
        {
            OperateResult resultInfo = new OperateResult();
            try
            {
                SchedulingSystemSoapClient service = new SchedulingSystemSoapClient();
                ResultHelperOfBoolean result = service.GetScheduleState(id.ToString());
                if (result.S) 
                {
                    resultInfo.Body = result.D;
                }
                else
                {
                    resultInfo.Result = 0;
                    resultInfo.Body = result.M;
                }
            }
            catch (Exception ex)
            {
                resultInfo.Result = 0;
                resultInfo.Body = ex.Message;
            }
            return resultInfo;
        }
    }
}
